﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using School.Entities;
using System.Collections;

namespace School.Service.Uniform
{
    public static class SRV_Clothe_PayOrder
    {
        private static SchoolEntities db = new SchoolEntities();
        public static bool OrderPayInsert(SRV_CLOTHES_PAYMENT_ORDER payOrder,out long orderId)
        {
            db.AddToSRV_CLOTHES_PAYMENT_ORDER(payOrder);
            try
            {
                db.SaveChanges();
                orderId = payOrder.Order_Id;
                return true;
            }
            catch
            {
                orderId = 0;
                return false;
            }
        }
        public static bool OrderDiscountInsert(Hashtable table)
        {
            try
            {
                foreach (DictionaryEntry item in table)
                {
                    db.AddToSRV_Clothe_PaymentDiscount(new SRV_Clothe_PaymentDiscount() { 
                    OrderID = long.Parse(item.Value.ToString()),
                    DiscountID = long.Parse(item.Key.ToString())
                    });
                }
                db.SaveChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }
        public static SRV_CLOTHES_PAYMENT_ORDER GetPaymentOrder(long paymntOrderNum,long SizeId)
        {
            try
            {
                SRV_CLOTHES_PAYMENT_ORDER query = (from payOrder in db.SRV_CLOTHES_PAYMENT_ORDER
                            where payOrder.Payment_Order_Number == paymntOrderNum && payOrder.Clothes_Size_Id == SizeId
                            select payOrder).FirstOrDefault();
                return query;
            }
            catch
            {
                return null;
            }
        }
    }
   
}
